4 struct MapGroup: View {
11 let cornerSize = CGSize(width: 2.0, height: 2.0)
12 var strokeSize: CGFloat { 1.75 * vertexSize.width }
15 let groupList = group.map({ vertex in
16 return [Double(vertex.position.x), Double(vertex.position.y)]
19 let hullPoints = hull.hull(groupList, nil)
20 return hullPoints.compactMap({ object in
21 if let point = object as? [Double] {
22 return CGPoint(x: point[0], y: point[1])
30 var initialMove: CGPoint?
33 let offsetPoint = CGPoint(x: w(point.x), y: h(point.y))
35 if initialMove == nil {
36 path.move(to: offsetPoint)
37 initialMove = offsetPoint
39 path.addLine(to: offsetPoint)
43 if let initialMove = initialMove {
44 path.addLine(to: initialMove)
49 CGAffineTransform(translationX: vertexSize.width / 2.0, y: vertexSize.height / 2.0)
55 lineWidth: strokeSize,
65 func h(_ dimension: CGFloat) -> CGFloat {
66 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
69 func w(_ dimension: CGFloat) -> CGFloat {
70 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
76 mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
78 Vertex(id: 0, label: "A Circle", position: CGPoint(x: 50.0, y: 50.0)),
79 Vertex(id: 1, label: "A Square", position: CGPoint(x: 10.0, y: 20.0), shape: .square),
80 Vertex(id: 2, label: "A triangle", position: CGPoint(x: 25, y: 32.0), shape: .triangle),
81 Vertex(id: 3, label: "An X", position: CGPoint(x: 70.0, y: 70.0), shape: .x),